
<template>
  <el-dialog
    v-model="conf.visible"
    title="修改 用户信息"
    width="30%"
    draggable
    :before-close="hide"
  >
<el-form :model="form" size="small" ref="form" :rules="rules">


 <!--姓名 输入控件 -->
 <el-form-item prop="full_name" label="姓名" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.full_name" maxlength="32"  placeholder="请输入姓名" />
 </el-form-item>

 <!--登录名 输入控件 -->
 <el-form-item prop="user_name" label="登录名" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.user_name" maxlength="64"  placeholder="请输入登录名" />
 </el-form-item>

 <!--邮件地址 输入控件 -->
 <el-form-item prop="email" label="邮件地址" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.email" maxlength="32"  placeholder="请输入邮件地址" />
 </el-form-item>

 <!--电话号码 输入控件 -->
 <el-form-item prop="mobile" label="电话号码" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.mobile" maxlength="12"  placeholder="请输入电话号码" />
 </el-form-item>

 <!--扩展参数 输入控件 -->
 <el-form-item prop="ext_params" label="扩展参数" label-width="100px" label-position="right">
   <el-input clearable style="width: 100%" v-model="form.ext_params" maxlength="1024"  type="textarea" show-word-limit  placeholder="请输入扩展参数" />
 </el-form-item>

  <!--状态 switch控件 -->
  <el-form-item prop="status" label="状态" label-width="100px" label-position="right">
    <el-switch v-model="form.status_switch" />
  </el-form-item>

  

</el-form>
    <template #footer>
      <span class="dialog-footer">
        <el-button @click="hide">取消</el-button>
        <el-button type="primary" @click="save">提交</el-button>
      </span>
    </template>
  </el-dialog>
</template>

<script>
export default {
  data() {
    return {
      conf: {
        visible: false,
        uploadPath:this.$theia.env.join("/file/upload"),
      },
    rules:{
      full_name:[{
          required:true,
          message:"请输入姓名",
          trigger: 'blur',
      }],
      user_name:[{
          required:true,
          message:"请输入登录名",
          trigger: 'blur',
      }],
      email:[{
          required:false,
          message:"请输入邮件地址",
          trigger: 'blur',
      }],
      mobile:[{
          required:true,
          message:"请输入电话号码",
          trigger: 'blur',
      }],
      ext_params:[{
          required:false,
          message:"请输入扩展参数",
          trigger: 'blur',
      }],
      status:[{
          required:true,
          message:"请输入状态",
          trigger: 'blur',
      }],
    },
    form:{
        full_name:"",
        user_name:"",
        email:"",
        mobile:"",
        ext_params:"",
        status_switch:false,
        },
      }},
  methods: {
    show(form) {
      this.conf.visible = true;
      this.get(form)
    },
      get(form){
        let that = this
        this.$theia.http.get("/userinfo",form).then(res=>{
          res.status_switch = res.status == 0
        Object.assign(that.form, res)
        }).catch(res=>{
          let code = res.response.status
          let msg = `用户信息查询失败(${code})`
          that.$notify.error({title: '失败',message:msg ,duration:5000})
        })
    },
    save(){
       this.form.status = this.form.status_switch?0:1;
        this.$refs.form.validate((v=>{
            if(v){
                this.onSave()
               
            }
        }))
    },
    onSave(){
        let that = this
        this.$theia.http.put("/userinfo",this.form).then(res=>{
            that.$notify.success({title: '成功',message: '用户信息保存成功',duration:5000})
            that.$emit("onsaved")
            that.hide()
        }).catch(res=>{
          let code = res.response.status
          let msg = `用户信息修改失败(${code})`
          that.$notify.error({title: '失败',message: msg,duration:5000})
        })
    },
    hide() {
      this.conf.visible = false;
      this.$refs.form.resetFields();
    },
     onUploadSuccess(response){
      
    },
  },
};
</script>

<style>
</style>